# -*- coding: utf-8 -*-
"""
@Time : 2023/12/15 7:45 PM
@Author: imamhusan
@Des: 描述
"""
import oss2
import os


class AliyunOss(object):

    def __init__(self):
        self.access_key_id = os.getenv('OSS_ACCESS_KEY_ID')
        self.access_key_secret = os.getenv('OSS_ACCESS_KEY_SECRET')
        self.auth = oss2.Auth(self.access_key_id, self.access_key_secret)
        self.bucket_name = os.getenv('OSS_BUCKET_NAME', 'ozhas-class')
        self.endpoint = os.getenv('OSS_ENDPOINT', 'oss-cn-beijing.aliyuncs.com')
        self.bucket = oss2.Bucket(self.auth, self.endpoint, self.bucket_name)

    def put_object_from_file(self, name, file):
        self.bucket.put_object_from_file(name, file)
        return "https://{}.{}/{}".format(self.bucket_name, self.endpoint, name)


# aliyunoss = AliyunOss()
# img_url = aliyunoss.put_object_from_file("upload/1.jpg", "oydex.png")



